home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / shadow-3.1.4 / spdbm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-26  |  1.2 KB  |  90 lines

  1. /*
  2.  * Copyright 1990, 1991, John F. Haugh II
  3.  * All rights reserved.
  4.  *
  5.  * Use, duplication, and disclosure prohibited without
  6.  * the express written permission of the author.
  7.  */
  8.  
  9. #ifndef    lint
  10. static    char    sccsid[] = "@(#)spdbm.c    3.3    08:46:22    9/12/91";
  11. #endif
  12.  
  13. #include <string.h>
  14. #include <stdio.h>
  15. #include "config.h"
  16. #include "shadow.h"
  17.  
  18. #ifdef    NDBM
  19. #include <ndbm.h>
  20. DBM    *sp_dbm;
  21.  
  22. /*
  23.  * sp_dbm_update
  24.  *
  25.  * Updates the DBM password files, if they exist.
  26.  */
  27.  
  28. int
  29. sp_dbm_update (sp)
  30. struct    spwd    *sp;
  31. {
  32.     datum    key;
  33.     datum    content;
  34.     char    data[BUFSIZ];
  35.     int    len;
  36.     static    int    once;
  37.  
  38.     if (! once) {
  39.         if (! sp_dbm)
  40.             setspent ();
  41.  
  42.         once++;
  43.     }
  44.     if (! sp_dbm)
  45.         return 0;
  46.  
  47.     len = spw_pack (sp, data);
  48.  
  49.     content.dsize = len;
  50.     content.dptr = data;
  51.  
  52.     key.dsize = strlen (sp->sp_namp);
  53.     key.dptr = sp->sp_namp;
  54.     if (dbm_store (sp_dbm, key, content, DBM_REPLACE))
  55.         return 0;
  56.  
  57.     return 1;
  58. }
  59.  
  60. /*
  61.  * sp_dbm_remove
  62.  *
  63.  * Updates the DBM password files, if they exist.
  64.  */
  65.  
  66. int
  67. sp_dbm_remove (user)
  68. char    *user;
  69. {
  70.     datum    key;
  71.     static    int    once;
  72.  
  73.     if (! once) {
  74.         if (! sp_dbm)
  75.             setspent ();
  76.  
  77.         once++;
  78.     }
  79.     if (! sp_dbm)
  80.         return 0;
  81.  
  82.     key.dsize = strlen (user);
  83.     key.dptr = user;
  84.     if (dbm_delete (sp_dbm, key))
  85.         return 0;
  86.  
  87.     return 1;
  88. }
  89. #endif
  90.